package com.part2.action.common.form;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.ValidatorForm;



public class CustomActionForm extends ValidatorForm implements
		java.io.Serializable {

	protected ValueObjectAssembler mBussinessObjectAssembler;
	protected Map mMultiAssembler;
	protected FileValueObjectAssembler mFileValueObjectAssembler;

	public CustomActionForm() {
		mBussinessObjectAssembler = new ValueObjectAssembler();
		mMultiAssembler = new HashMap();
		mFileValueObjectAssembler = new FileValueObjectAssembler();
	}

	public String[] getMultiString(String pName) {
		if (mMultiAssembler.get(pName) == null)
			return null;
		return (String[]) mMultiAssembler.get(pName);
	}

	public void setMultiString(String pName, String[] multiString) {
		if (mMultiAssembler == null)
			mMultiAssembler = new HashMap();
		mMultiAssembler.put(pName, multiString);
	}

	public ValueObjectAssembler getVoa() {
		if (mBussinessObjectAssembler == null)
			mBussinessObjectAssembler = new ValueObjectAssembler();
		return mBussinessObjectAssembler;
	}

	public void setVoa(ValueObjectAssembler pBussinessObjectAssembler) {
		mBussinessObjectAssembler = pBussinessObjectAssembler;
	}

	public void addVoa(ValueObjectAssembler pBussinessObjectAssembler) {
		mBussinessObjectAssembler.add(pBussinessObjectAssembler);
	}

	public FileValueObjectAssembler getFoa() {
		return mFileValueObjectAssembler;
	}

	public void setFoa(FileValueObjectAssembler pFileValueObjectAssembler) {
		mFileValueObjectAssembler = pFileValueObjectAssembler;
	}

	public void addFoa(FileValueObjectAssembler pFileValueObjectAssembler) {
		mFileValueObjectAssembler.add(pFileValueObjectAssembler);
	}

	/**
	 * Reset all properties to their default values.
	 * 
	 * @param mapping
	 *            The mapping used to select this instance
	 * @param request
	 *            The servlet request we are processing
	 */
	public void reset(ActionMapping mapping,
			javax.servlet.http.HttpServletRequest request) {
	}

	public ActionErrors validate(ActionMapping mapping,
			javax.servlet.http.HttpServletRequest request) {// GEN-END:0#reset-
															// method

		ActionErrors errors = super.validate(mapping, request);// GEN-END:0#
																// validate
																// -method-top

		if (errors == null || errors.isEmpty()) {
			// we have no errors
			return null;
		}
		return errors;
	}

	public String toString() {
		return getVoa().toString();
	}
}
